package com.xianzhi.controller.system;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.xianzhi.bean.User;
import com.xianzhi.constant.PagecodeEnum;
import com.xianzhi.constant.SessionKeyConst;
import com.xianzhi.dto.UserDto;
import com.xianzhi.service.UserService;

@Controller
@RequestMapping("/ad")
public class UserController {
	@Autowired 
	private UserService userService;
	@Autowired
	private HttpSession session;
	@RequestMapping("/login")
	public String login(UserDto userDto, RedirectAttributes attr){
		if (userService.login(userDto)) {
			session.setAttribute(SessionKeyConst.USER_INFO, userDto);
			return "redirect:/index";
		}
		attr.addFlashAttribute(PagecodeEnum.KEY, PagecodeEnum.LOGIN_FAIL);
		return "redirect:/login";
		
	}
}
